package untils;

import java.io.*;

public class FileUtils {
    // 单字节复制
    public static void copySingleByte(InputStream in, OutputStream out) throws IOException {
        int readData;
        // 边读边写
        while ((readData = in.read()) != -1) {
            out.write(readData);
        }

    }

    // 字节数组复制
    public static void copyMultiBytes(InputStream in, OutputStream out) throws IOException{
        int readCount;
        byte[] bytes = new byte[1024];
        // 边读边写
        while ((readCount = in.read(bytes)) != -1) {
            out.write(bytes, 0, readCount);
        }

    }

    // 单字符复制
    public static void copySingleChar(Reader reader, Writer writer) throws IOException {
        int readData; // 表示字符值
        while ((readData = reader.read()) != -1) {
            writer.write(readData);
        }
    }

    // 字符数组方式复制
    public static void copyMultiChars(Reader reader, Writer writer) throws IOException {
        int readCount; // 表示读取到的字符个数
        char[] chars = new char[1024];
        while ((readCount = reader.read(chars)) != -1) {
            writer.write(chars, 0, readCount);
        }
    }
}
